package controller;

import common.Constant;
import common.util.Constants;
import model.dto.SysUserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import service.SysUsersService;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @className: controller.LoginController
 * @author: Xia
 * @create: 2023-03-09 11:53
 */
@Controller
public class LoginController {

    @Autowired
    private SysUsersService service;

    @RequestMapping("/")
    public String toLogin(){
        return "login";
    }
    @RequestMapping("doLogin")
    public String login(String account , String password , Model model , HttpSession session){
        SysUserDto sysUser = service.getSysUser(account, password);
        if (sysUser == null){
            model.addAttribute(Constant.ERROR,"登陆失败");
            return "forward:/";
        }
        session.setAttribute(Constant.USER_SESSION,sysUser);
        return "redirect:main";
    }
    @RequestMapping("main")
    public String toMain(){
        return "main";
    }


}
